home *** CD-ROM | disk | FTP | other *** search
- # include "Shell.h"
-
- extern Boolean doneflag;
-
- /* These are stolen from arith.c, so we don't have to include the ANSI library for
- 2 routines */
- int
- abs(int i)
- {
- if (i < 0)
- return(-i);
- return(i);
- }
-
-
- long
- labs(long i)
- {
- if (i < 0)
- return(-i);
- return(i);
- }
-
-
- /****************************************************
- Quickdraw Things...
- *****************************************************/
-
- /*------------------------------------------------------------------------
- NewPixImage() Creates pix image and inits the fields of the pixmap...
- ------------------------------------------------------------------------*/
-
- Boolean NewPixImage(PixMapHandle ThePix, Rect *TheRect, short dpth)
- {
- Ptr ThePtr;
- long Offrowbytes, ptrsize;
-
- Offrowbytes =(((dpth * (TheRect->right - TheRect->left)) + 15) / 16) * 2;
- ptrsize = (TheRect->bottom - TheRect->top) * Offrowbytes;
- ThePtr = NewPtr(ptrsize);
- if(MemError() != noErr)
- return(false);
-
- (**ThePix).baseAddr = ThePtr;
- (**ThePix).rowBytes = Offrowbytes + 0x8000;
- (**ThePix).bounds = *TheRect;
- (**ThePix).pixelSize = dpth;
- (**ThePix).cmpCount = 1;
- (**ThePix).cmpSize = dpth;
- return(true);
- }
-
-
- /*------------------------------------------------------------------------
- NewBitMap() Creates bit image and inits the fields of the bitmap...
- ------------------------------------------------------------------------*/
-
- Boolean NewBitMap(BitMap *TheMap, Rect *TheRect)
- {
- long rb;
- Ptr ba;
-
- rb = ((TheRect->right - TheRect->left + 15) / 16) * 2;
- ba = NewPtr(rb * (TheRect->bottom - TheRect->top));
- if( MemError() == noErr)
- {
- TheMap->rowBytes = rb;
- TheMap->baseAddr = ba;
- TheMap->bounds = *TheRect;
- return(true);
- }
- else
- return(false);
- }
-
- /*-------------------------------------------------------------------------
- CenterRect() Centers theRect over thePt...
- --------------------------------------------------------------------------*/
- void CenterRect(Rect *theRect, Point *thePt)
- {
- /* First home theRect... */
-
- OffsetRect(theRect, -theRect->left, -theRect->top);
-
- /* ...then center it over thePt */
-
-
- thePt->h = thePt->h - (theRect->right / 2);
- thePt->v = thePt->v - (theRect->bottom / 2);
- OffsetRect(theRect, thePt->h, thePt->v);
- }
-
- /*-------------------------------------------------------------------------
- Center() Returns the center of the rect
- --------------------------------------------------------------------------*/
- Point Center(Rect *theRect)
- {
- Point pt;
-
- pt.h = theRect->left + ((theRect->right - theRect->left) / 2);
- pt.v = theRect->top + ((theRect->bottom - theRect->top) / 2);
- return(pt);
- }
-
-
- /*-------------------------------------------------------------------------
- These routines are from DTS Utilities
- --------------------------------------------------------------------------*/
- short NumToolboxTraps(void)
- {
- if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap))
- return (0x200);
- else
- return (0x400);
- }
-
- TrapType GetTrapType(short theTrap)
- {
- /* OS traps start with A0, Tool with A8 or AA. */
- if ((theTrap & 0x0800) == 0) /* per D.A. */
- return (OSTrap);
- else
- return (ToolTrap);
- }
-
- Boolean TrapAvailable(short theTrap)
- {
- TrapType theTrapType;
-
- theTrapType = GetTrapType(theTrap);
- if ((theTrapType == ToolTrap) && ((theTrap &= 0x07FF) >= NumToolboxTraps()))
- theTrap = _Unimplemented;
-
- return (NGetTrapAddress(_Unimplemented, ToolTrap) != NGetTrapAddress(theTrap,
- theTrapType));
- }
-